﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace MoneyBook.Navigation {
    public class NavigationMessageHandleBehavior : Behavior<Frame> {

        protected override void OnAttached() {
            base.OnAttached();

            if (NavigationMessageService.Curret != null) {
                NavigationMessageService.Curret.RequestNavigation += OnRequestNavigation;
            }
        }

        protected override void  OnDetaching()
        {
 	         base.OnDetaching();

             if (NavigationMessageService.Curret != null) {
                 NavigationMessageService.Curret.RequestNavigation -= OnRequestNavigation;
             }
        }

        private void OnRequestNavigation(object sender, RequestNavigationEventArgs e) {
            if(this.AssociatedObject == null){
                return;
            }
            this.AssociatedObject.Navigate(e.Uri);
        }

    }
}
